<template>
  <div class="header">
    <div class="header-left">
      <div
        class="icon iconfont icon-duosefuzhu-gengduotiaojian"
        v-ripple
        @click="toggleContentSidebar"
      ></div>
      <router-link to="/" class="img-wrap">
        <img
          v-show="true"
          src="https://img.ezgskin.com/logo/21skins-logo.png"
        />
      </router-link>
    </div>
    <div class="header-middle">
      <hr />
      <router-link to="/mall" class="middle-item">
        <i class="icon iconfont icon-shipinshangcheng"> </i>
        <span class="text">饰品商城</span>
      </router-link>
      <router-link to="/user/withdraw" class="middle-item">
        <i class="icon iconfont icon-shipinbeibao"> </i>
        <span class="text">饰品背包</span>
      </router-link>
      <router-link to="/user/payment" class="middle-item">
        <i class="icon iconfont icon-chongzhiqia1"> </i>
        <span class="text">充值</span>
        <span class="detail">首冲 100 送 13</span>
      </router-link>
    </div>
    <div class="header-right">
      <div
        class="register"
        v-ripple="{ color: '#02bf4d' }"
        @click="openRegister"
      >
        注册
      </div>
      <div class="login" v-ripple @click="openLogin">登录</div>
    </div>
  </div>
</template>
<script type="text/ecmascript-6">
import { mapActions, mapMutations, mapGetters } from 'vuex'
import { throttle } from 'assets/js/util'
import AuthModule from 'views/login/login.js'
const authModule = new AuthModule()

export default {
  data() {
    return {}
  },
  computed: {
    ...mapGetters('sidebar', [
      'contentSidebarState',
      'contentSidebarStatemineSidebarState',
      'contentSidebarStatescreenSize'
    ])
  },
  methods: {
    ...mapMutations('sidebar', {
      setScreenSize: 'setScreenSize'
    }),
    ...mapActions('sidebar', [
      'showContentSidebar',
      'hideContentSidebar',
      'showMineSidebar',
      'hideMineSidebar'
    ]),
    toggleContentSidebar() {
      if (this.contentSidebarState) {
        this.hideContentSidebar()
        return
      }
      this.showContentSidebar()
    },
    toggleMineSidebar() {

      if (!authModule.verify()) {
        authModule.open()
        return
      }

      if (this.mineSidebarState) {
        this.hideMineSidebar()
        return
      }
      this.showMineSidebar()
    },
    openRegister() {
      if (!authModule.verify()) {
        authModule.open('register')
        return
      }
    },
    openLogin() {
      if (!authModule.verify()) {
        authModule.open('login')
        return
      }
    }
  },
  mounted() {
    this.resizeHandle = throttle(() => {
      let screenSize = document.body.offsetWidth
      this.setScreenSize(screenSize)
    })

    window.addEventListener('resize', this.resizeHandle)
    this.resizeHandle()
  },
  destroyed() {
    window.removeEventListener('resize', this.resizeHandle)
  },
}
</script>

<style lang="stylus" scoped ref="stylesheet/stylus">
@import '~assets/stylus/variable.styl';

.header {
  z-index: 100;
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 60px;
  box-shadow: 0px 2px 4px -1px rgba(0, 0, 0, 0.2), 0px 4px 5px 0px rgba(0, 0, 0, 0.14), 0px 1px 10px 0px rgba(0, 0, 0, 0.12);
  display: flex;
  align-items: center;
  background: url('./img/headerBackground.jpg') #26262f;
  overflow: hidden;

  .header-left {
    display: flex;
    align-items: center;
    height: 46px;
    width: 250px;

    .icon {
      position: relative;
      font-size: 21px;
      padding: 16px;
      border-radius: 20%;
      color: #848492;
      overflow: hidden;
    }

    .img-wrap {
      display: inline-block;

      // background: #fff;
      img {
        height: 100%;
        width: 100%;
      }
    }
  }

  .header-middle {
    flex: 1;
    height: 20px;
    display: flex;
    align-items: center;
    font-size: 16px;

    hr {
      position: relative;
      top: 1px;
      display: inline-block;
      height: 100%;
      width: 1px;
      background-color: #848492;
    }

    .middle-item {
      margin-left: 16px;
      height: 100%;

      .text {
        margin-left: 8px;
        font-size: 15px;
      }

      .detail {
        color: #1a1c24;
        display: inline-block;
        padding: 0 10px;
        position: relative;
        font-size: 14px;
        margin-left: 8px;
        border-radius: 5px;
        background-color: #02bf4d;
        box-sizing: border-box;
        height: 18px;
        line-height: 18px;

        &::after {
          width: 0;
          content: '';
          top: 50%;
          left: -4px;
          color: #02bf4d;
          position: absolute;
          border-top: 4px solid transparent;
          margin-top: -4px;
          border-right: 4px solid;
          border-bottom: 4px solid transparent;
        }
      }

      &:hover {
        color: $icon-actived-color;
      }

      &.router-link-active {
        color: $icon-actived-color;
      }
    }
  }

  .header-right {
    display: flex;
    align-items: center;

    div {
      position: relative;
      padding: 0;
      margin-right: 16px;
      min-width: 105px;
      height: 43.3px;
      line-height: 43.3px;
      font-size: 16px;
      font-weight: 600;
      text-align: center;
      outline: none;
      border: none;
      background: none;
      border-radius: 5px;
      transition: background-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
    }

    .register {
      color: #02bf4d;
      border-color: #02bf4d;
      border: 1px solid #02bf4d;

      &:hover {
        background-color: rgba(195, 195, 226, 0.04);
      }
    }

    .login {
      background-color: #02bf4d;
      color: #1a1c24;
      border: 1px solid #25252f;

      &:hover {
        background-color: #00e359;
      }
    }
  }
}

@media screen and (min-width: 1280px) {
  .header {
    .header-left {
      height: 46px;
      width: 250px;

      .icon {
        display: none;
      }

      .img-wrap {
        margin-left: 6px;
        height: 46px;
        width: 205px;
      }
    }
  }
}

@media screen and (max-width: 1280px) {
  .header {
    .header-left {
    }

    .header-middle {
      display: none;
    }

    .header-right {
      margin-left: auto;
    }
  }
}

@media screen and (min-width: 500px) {
  .header {
    .header-left {
      height: 46px;
      width: 250px;

      .img-wrap {
        margin-left: 6px;
        height: 46px;
        width: 205px;
      }
    }

    .header-middle {
    }
  }
}

@media screen and (max-width: 500px) {
  .header {
    .header-left {
      height: 46px;
      width: 250px;

      .img-wrap {
        height: 30px;
        width: 133px;
      }
    }
  }
}

@media screen and (max-width: 600px) {
  .header {
    height: 56px;

    .header-right {
      div {
        position: relative;
        padding: 0;
        margin-right: 8px;
        min-width: 70px;
        height: 30px;
        line-height: 30px;
        font-size: 13px;
        font-weight: 600;
        text-align: center;
        border-radius: 5px;
      }
    }
  }
}
</style>
